<?php
namespace controller\login;
require_once '../model/model.php';
use admin\Model\model as m;


$m = new m();

//删除数据
$id = null;
if (!empty($_POST['oper']) && $_POST['oper'] == 'del') {
	if (!empty($_POST['id'])) {
		$id = $_POST['id'];
		exit($m->del('user',$id));
	}
}else if (!empty($_POST['oper']) && $_POST['oper'] == 'edit') {
	if (!empty($_POST['id'])) {
		$id = $_POST['id'];
		$user_id = $_POST['user_id'];
		$arr = $m->user_info($user_id);
		$name = $arr[0]['name'];
		$m_day = date("t");
		$on_day = $_POST['on_day'];
		$on_abs = $_POST['on_abs'];
		$is_tr = $_POST['is_tr'];
		$is_le = $_POST['is_le'];
		$add = $_POST['add'];
		$fk = $_POST['fk'];
		$basic = $_POST['basic'];
		$pay = $basic/21.75*$on_day*(21.75/$m_day)-$fk+$add;// 薪资计算公式：基本工资÷日工资(21.75)×出勤天数×(日工资÷月工作日)-罚款+奖金  @ $row['pay']
		exit($m->update('user',$id,$name,$m_day,$on_day,$on_abs,$is_tr,$is_le,$add,$fk,$basic,$pay,$user_id));
	}
}else if (!empty($_POST['oper']) && $_POST['oper'] == 'add') {
	if (!empty($_POST['id'] && $_POST['id'] == '_empty')) {
		
		$user_id = $_POST['user_id'];
		$arr = $m->user_info($user_id);
		$name = $arr[0]['name'];
		$m_day = date("t");
		$on_day = $_POST['on_day'];
		$on_abs = $_POST['on_abs'];
		$is_tr = $_POST['is_tr'];
		$is_le = $_POST['is_le'];
		$add = $_POST['add'];
		$fk = $_POST['fk'];
		$basic = $_POST['basic'];
		$pay = $basic/21.75*$on_day*(21.75/$m_day)-$fk+$add;// 薪资计算公式：基本工资÷日工资(21.75)×出勤天数×(日工资÷月工作日)-罚款+奖金  @ $row['pay']
		$mon = date('Y-m');
		exit($m->add('user',$name,$m_day,$on_day,$on_abs,$is_tr,$is_le,$add,$fk,$basic,$pay,$mon,$user_id));
	}
}